package cn.lrwjz.androidguide.ui;

import android.os.Bundle;
import android.view.MenuItem;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.google.android.material.appbar.MaterialToolbar;
import com.google.android.material.navigationrail.NavigationRailView;
import com.google.android.material.navigation.NavigationBarView;

import cn.lrwjz.androidguide.R;

public class NavigationRailActivity extends AppCompatActivity {
    private TextView contentText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_navigation_rail);

        MaterialToolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setTitle("Navigation Rail 示例");
        }

        contentText = findViewById(R.id.contentText);
        NavigationRailView navigationRail = findViewById(R.id.navigationRail);
        
        navigationRail.setOnItemSelectedListener(new NavigationBarView.OnItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                int itemId = item.getItemId();
                if (itemId == R.id.nav_home) {
                    contentText.setText("首页内容");
                    return true;
                } else if (itemId == R.id.nav_dashboard) {
                    contentText.setText("仪表盘内容");
                    return true;
                } else if (itemId == R.id.nav_notifications) {
                    contentText.setText("通知内容");
                    return true;
                } else if (itemId == R.id.nav_settings) {
                    contentText.setText("设置内容");
                    return true;
                }
                return false;
            }
        });

        // 默认选中首页
        navigationRail.setSelectedItemId(R.id.nav_home);
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
} 